package com.it.tanhua.dubbo.server.apiImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.it.tanhua.dubbo.server.api.RecommendUserApi;
import com.it.tanhua.dubbo.server.pojo.RecommendUser;
import com.it.tanhua.dubbo.server.vo.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * @author xukang
 * @date 2021-08-16 18:18
 */
@Service(version = "1.0.0")
public class RecommendUserApiImpl implements RecommendUserApi {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public RecommendUser queryWithMaxScore(Long userId) {
        Criteria toUserId = Criteria.where("toUserId").is(userId);
        Query query = new Query(toUserId).with(Sort.by(Sort.Order.desc("score")));;
        return mongoTemplate.findOne(query, RecommendUser.class);
    }

    @Override
    public PageInfo<RecommendUser> queryPageInfo(Long userId, Integer pageNum, Integer pageSize) {
        return null;
    }
}
